
var getObject = {
	getxinzuo:function (){
		ajax({
			type:'get',
			url:'../data/data.json',
			dataType:"json",
			success:function(msg){ 
			    getObject.getdata(msg.car);
			}, 
			error:function(){ 
			    console.log("error") 
			} 
		})
	},
	getdata:function (data){
		var str = '<ul class="swiper-wrapper nav_list">';
		for (var i=0;i<data.length;i++) {
			str += '<li class="swiper-slide list" index='+data[i].MusicOrderCode+'>'+data[i].OrderName+'</li>';
		}
		str += '</ul>';
		document.querySelector('.swiper-container').innerHTML=str;
		//控制
        var Swiper1 = new Swiper('#swiper-container1', {
            prevButton: '.swiper-button-prev',
            nextButton: '.swiper-button-next',
            initialSlide :5,
            onSlideChangeEnd:function(swiper){
            	document.querySelector('#swiper-container2').children[0].src = data[swiper.activeIndex].car_url;
            }
        })
        var Swiper2 = new Swiper('#swiper-container2', {
            effect: 'fade',
            initialSlide :5
        })
        Swiper1.params.control = Swiper2;//需要在Swiper2初始化后，Swiper1控制Swiper2
        Swiper2.params.control = Swiper1;//需要在Swiper1初始化后，Swiper2控制Swiper1
	},
	evclick:function(ele){
		ele.onclick = function(){
			var obj = {};
			obj.carcode = document.querySelector('.swiper-slide-active').getAttribute('index');
			obj.carname = document.querySelector('.swiper-slide-active').innerText;
			obj.carurl = document.querySelector('#swiper-container2').children[0].src;
			console.log(obj)
			localStorage.setItem('carcode',obj.carcode);
			localStorage.setItem('carname',obj.carname);
			localStorage.setItem('carurl',obj.carurl);
			console.log(localStorage);
			window.location = 'music.html'
		}
	}
	
}
getObject.getxinzuo();
getObject.evclick(document.querySelector('.sec'))
